import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-03-25
 * Time: 16:46
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int sum = 0;
        int k = n / 10;
        int[][] arr = new int[10][n];
        int[] count = new int[10];
        for (int i = 0; i < n; i++) {
            int j = scan.nextInt();
            arr[j][count[j]++] = scan.nextInt();
        }
        for (int i = 0; i < 10; i++) {
            Arrays.sort(arr[i], 0, count[i]);
            for (int j = 0; j < count[i] - k; j++) {
                sum += arr[i][j];
            }
        }
        System.out.println(sum);
        scan.close();
    }
}
